home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QRZ! Ham Radio 8
/
QRZ Ham Radio Callsign Database - Volume 8.iso
/
pc
/
files
/
t_unix
/
bs941029.tgz
/
bbsx-941029.tar
/
bbsx
/
transfer.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-29
|
3KB
|
144 lines
#ifndef __lint
static char rcsid[] = "@(#) $Header: /home/dg1rtf/tcp/bbsx/RCS/transfer.c,v 1.2 1994/06/07 05:57:12 dg1rtf Exp $";
#endif
#define _HPUX_SOURCE
#include <stdio.h>
#include <fcntl.h>
#include <pwd.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/syslog.h>
#include "bbs.h"
#include "bbs.hd"
extern char *optarg;
extern int optint;
const struct cmdtable cmdtable[1];
/*---------------------------------------------------------------------------*/
int main(int argc, char **argv)
{
static int fdindex;
char src[80], dest[80];
char *p;
struct index index;
int c,signif;
int err_flag =0;
int delete =0, timestamp =0, at=0;
int count=0;
struct passwd *pw;
int i=1;
if (getuid()) {
pw = getpwnam(bbsadm);
if(getuid() != pw->pw_uid) {
perror("permission denied");
return 1;
}
}
if (chdir(WRKDIR)) {
mkdir(WRKDIR, 0755);
if(chdir(WRKDIR)) halt();
}
read_config();
if ((fdindex = open(INDEXFILE, O_RDWR, 0644)) < 0) goto stop;
while ((c = getopt(argc, argv, "d:at")) != EOF) {
switch (c) {
case 'd':
delete=1;
strcpy(src,optarg);
break;
case 't':
timestamp=1;
i++;
break;
case 'a':
at=1;
i++;
break;
case '?':
err_flag=1;
break;
default:
err_flag=1;
break;
}
}
if (argc < 3) err_flag = 1;
if (err_flag) {
puts("usage: transfer [-a] [-t] [-d] source [destination]");
exit(1);
}
if (!delete) {
strcpy(src,argv[i]);strcpy(dest,argv[i+1]);
if (strlen(src) > 8)
src[8]= 0;
if (strlen(dest) > 8)
dest[8]= 0;
}
for (; ; ) {
if (read(fdindex, (char *) &index, sizeof(index)) != sizeof(index)) goto stop;
if (!(index.flags & DELETED)) {
strupc(src);strupc(dest);
p=strchr(src,'*');
if (p)
signif = p-src;
else
signif = (strlen(src) > strlen(index.to)) ? strlen(src) : strlen(index.to);
if (signif > 8)
signif = 8;
if (!strncmp(index.to,src,signif)) {
count++;
if (delete) {
unlink(getfilename(index.mesg));
index.flags |= DELETED;
if (lseek(fdindex, -sizeof(struct index), SEEK_CUR) < 0) return -1;
if (write(fdindex, &index, sizeof(struct index)) !=
sizeof(struct index))
return -1;
}
else {
strcpy(index.to,dest);
if (lseek(fdindex, -sizeof(struct index), SEEK_CUR) < 0) return -1;
if (index.to[1] == 0) {
if (timestamp) {
index.date = time((long *) 0);
}
if (at) {
strcpy(index.at,Myhostname);
}
} else
getalias(index.to);
if (write(fdindex, &index, sizeof(struct index)) != sizeof(struct index))
return -1;
}
}
}
}
stop:
close(fdindex);
if (delete) {
printf("%d %s\n",count," messages deleted") ;
}
else {
printf("%d %s\n",count," messages transfered");
}
return 0;
}